package store.util;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import store.pay.icbc.IcbcB2cPayObject;
import store.pay.icbc.IcbcB2cPayResultObject;

public class XmlParser extends DefaultHandler {

	private IcbcB2cPayObject icbcB2cPayObject;
	private IcbcB2cPayResultObject icbcB2cPayResultObject;

	private String tagValue;

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		if ("B2CReq".equals(qName) || "B2CRes".equals(qName)) {
			icbcB2cPayObject = new IcbcB2cPayObject();
			icbcB2cPayResultObject = new IcbcB2cPayResultObject();
		}
	}

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		tagValue = new String(ch, start, length).trim();
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		if ("interfaceName".equals(qName)){
			icbcB2cPayObject.setInterfaceName(tagValue);
			icbcB2cPayResultObject.setInterfaceName(tagValue);
		}
		if ("interfaceVersion".equals(qName)){
			icbcB2cPayObject.setInterfaceVersion(tagValue);
			icbcB2cPayResultObject.setInterfaceVersion(tagValue);
		}
		if ("orderDate".equals(qName)){
			icbcB2cPayObject.setOrderDate(tagValue);
			icbcB2cPayResultObject.setOrderDate(tagValue);
		}
		if ("curType".equals(qName)){
			icbcB2cPayObject.setCurType(tagValue);
			icbcB2cPayResultObject.setCurType(tagValue);
		}
		if ("merID".equals(qName)){
			icbcB2cPayObject.setMerID(tagValue);
			icbcB2cPayResultObject.setMerID(tagValue);
		}
		if ("orderid".equals(qName)){
			icbcB2cPayObject.setOrderid(tagValue);
			icbcB2cPayResultObject.setOrderid(tagValue);
		}
		if ("amount".equals(qName)){
			icbcB2cPayObject.setAmount(tagValue);
			icbcB2cPayResultObject.setAmount(tagValue);
		}
		if ("installmentTimes".equals(qName)){
			icbcB2cPayObject.setInstallmentTimes(tagValue);
			icbcB2cPayResultObject.setInstallmentTimes(tagValue);
		}
		if ("merAcct".equals(qName)){
			icbcB2cPayObject.setMerAcct(tagValue);
			icbcB2cPayResultObject.setMerAcct(tagValue);
		}
		if ("goodsID".equals(qName)){
			icbcB2cPayObject.setGoodsID(tagValue);
		}
		if ("goodsName".equals(qName)){
			icbcB2cPayObject.setGoodsName(tagValue);
		}
		if ("goodsNum".equals(qName)){
			icbcB2cPayObject.setGoodsNum(tagValue);
		}
		if ("carriageAmt".equals(qName)){
			icbcB2cPayObject.setCarriageAmt(tagValue);
		}
		if ("verifyJoinFlag".equals(qName)){
			icbcB2cPayObject.setVerifyJoinFlag(tagValue);
			icbcB2cPayResultObject.setVerifyJoinFlag(tagValue);
		}
		if ("Language".equals(qName)){
			icbcB2cPayObject.setLanguage(tagValue);
		}
		if ("creditType".equals(qName)){
			icbcB2cPayObject.setCreditType(tagValue);
		}
		if ("notifyType".equals(qName)){
			icbcB2cPayObject.setNotifyType(tagValue);
		}
		if ("resultType".equals(qName)){
			icbcB2cPayObject.setResultType(tagValue);
		}
		if ("merReference".equals(qName)){
			icbcB2cPayObject.setMerReference(tagValue);
		}
		if ("merCustomIp".equals(qName)){
			icbcB2cPayObject.setMerCustomIp(tagValue);
		}
		if ("goodsType".equals(qName)){
			icbcB2cPayObject.setGoodsType(tagValue);
		}
		if ("merCustomID".equals(qName)){
			icbcB2cPayObject.setMerCustomID(tagValue);
		}
		if ("merCustomPhone".equals(qName)){
			icbcB2cPayObject.setMerCustomPhone(tagValue);
		}
		if ("goodsAddress".equals(qName)){
			icbcB2cPayObject.setGoodsAddress(tagValue);
		}
		if ("merOrderRemark".equals(qName)){
			icbcB2cPayObject.setMerOrderRemark(tagValue);
		}
		if ("merHint".equals(qName)){
			icbcB2cPayObject.setMerHint(tagValue);
		}
		if ("remark1".equals(qName)){
			icbcB2cPayObject.setRemark1(tagValue);
		}
		if ("remark2".equals(qName)){
			icbcB2cPayObject.setRemark2(tagValue);
		}
		if ("merURL".equals(qName)){
			icbcB2cPayObject.setMerURL(tagValue);
		}
		if ("merVAR".equals(qName)){
			icbcB2cPayObject.setMerVAR(tagValue);
		}
		if ("tranSerialNo".equals(qName)){
			icbcB2cPayResultObject.setTranSerialNo(tagValue);
		}
		if ("JoinFlag".equals(qName)){
			icbcB2cPayResultObject.setJoinFlag(tagValue);
		}
		if ("UserNum".equals(qName)){
			icbcB2cPayResultObject.setUserNum(tagValue);
		}
		if ("TranBatchNo".equals(qName)){
			icbcB2cPayResultObject.setTranBatchNo(tagValue);
		}
		if ("notifyDate".equals(qName)){
			icbcB2cPayResultObject.setNotifyDate(tagValue);
		}
		if ("tranStat".equals(qName)){
			icbcB2cPayResultObject.setTranStat(tagValue);
		}
		if ("comment".equals(qName)){
			icbcB2cPayResultObject.setComment(tagValue);
		}
	}

	public IcbcB2cPayObject getIcbcB2cPayObject() {
		return icbcB2cPayObject;
	}

	public IcbcB2cPayResultObject getIcbcB2cPayResultObject() {
		return icbcB2cPayResultObject;
	}
}
